package 面向对象_中.fobject类的使用.tostring方法;

import java.util.Objects;

/**
 * @Projectname java_based
 * @Filename CustomerTest
 * @Author an
 * @Data 2022/7/2 11:02
 * @Description TODO
 */
public class Customer {

    private String name;
    private int age;
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public Customer() {
        super();
    }
    public Customer(String name, int age) {
        super();
        this.name = name;
        this.age = age;
    }


    //自动生成的equals()

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Customer customer = (Customer) o;
        return age == customer.age && name.equals(customer.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }


    //自动生成
//    @Override
//    public String toString() {
//        return "Customer{" +
//                "name='" + name + '\'' +
//                ", age=" + age +
//                '}';
//    }

    //手写
        public String toString() {
        return "Customer[" +
                "name='" + name +
                ", age=" + age +
                ']';
    }
}
